<%--
  Created by IntelliJ IDEA.
  User: zl
  Date: 2021/11/29
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/layui/layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/layui/css/layui.css"/>
</head>
<body>
<div class=" ">
    <div class=" ">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">全局查询</label>
                            <div class="layui-input-inline">
                                <input type="text" name="pname" autocomplete="off"  name="all" id="all"  class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="searchBtn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">新增</button>
            </div>
        </script>

         <table class="layui-hide" id="teaTable" lay-filter="teaTable"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
<%--            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="send">发货</a>--%>
        </script>
    </div>
</div>
<%-- 新增表单--%>
<form class="layui-form" action="" lay-filter="biaodan"  style="display: none" id="addform">
    <input id="pid" name="pid" hidden>

    <div class="layui-form-item">
        <label class="layui-form-label">订单人姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="pname"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户id</label>
        <div class="layui-input-inline">
            <input type="text" name="uid"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单编号</label>
        <div class="layui-input-inline">
            <input type="text" name="order_number"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">总数量</label>
        <div class="layui-input-inline">
            <input type="text" name="total_count"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">总金额</label>
        <div class="layui-input-inline">
            <input type="text" name="total_price"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-inline">
            <input type="text" name="address"   placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div><div class="layui-form-item">
    <label class="layui-form-label">发货的快递名称</label>
    <div class="layui-input-inline">
        <input type="text" name="express"   placeholder="" autocomplete="off" class="layui-input">
    </div>
</div><div class="layui-form-item">
    <label class="layui-form-label">退货原因</label>
    <div class="layui-input-inline">
        <input type="text" name="salesreason"   placeholder="" autocomplete="off" class="layui-input">
    </div>
</div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
<%--            <input type="text" name="status"   placeholder="" autocomplete="off" class="layui-input">--%>
    <select name="status" lay-filter="status" id="status">

    </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<%--<script type="text/javascript" id="tm">
    {{#if (d.pdate!=0) { }}
        <div>{{layui.util.toDateString(d.pdate)}}</div>
        {{ #}else{ }}
</script>--%>

<script>
    layui.use(["table","form","jquery"],function (){
        var table=layui.table;
        var form=layui.form;
        var $=layui.jquery;
        //执行一个 table 实例
        table.render({
            elem:'#teaTable',
            url:'/order/selectTeacher2',
            toolbar:'#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'pid', title: '订单申请id', width:120, sort: true, fixed: 'left' }
            ,{field: 'pname', title: '订单人姓名', width:120}
            ,{field: 'uid', title: '用户id', width: 120, sort: true, totalRow: true}
            ,{field: 'order_number', title: '订单编号', width:120, sort: true}
            ,{field: 'total_count', title: '总数量', width:150, sort: true}
            ,{field: 'total_price', title: '总金额', width:120, sort: true}
            ,{field: 'address', title: '地址', width:120, sort: true}
            ,{field: 'express', title: '发货的快递名称', width:120, sort: true}
            ,{field: 'rname', title: '处理人', width:120, sort: true}
            ,{field: 'pdate', title: '下单日期', width:120, sort: true,
                    templet:"<div>{{layui.util.toDateString(d.pdate*1000, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
            ,{field: 'status', title: '状态', width:120,
                    templet: function (d) {
                        if (d.status == 0){
                            return "<button class='layui-btn layui-btn-xs layui-btn-radius layui-btn-warm disabled'>待发货</button>";
                        }else if(d.status == 1) {
                            return "<button class='layui-btn layui-btn-xs layui-btn-radius disabled'>已发货</button>";
                        }else if(d.status == 2) {
                            return "<button class='layui-btn layui-btn-xs layui-btn-danger layui-btn-radius disabled'>订单关闭</button>";
                        }else if(d.status == 3) {
                            return "<button class='layui-btn layui-btn-xs layui-btn-radius disabled'>已收货</button>";
                        }else if(d.status == 4) {
                            return "<button class='layui-btn layui-btn-xs layui-btn-danger layui-btn-radius disabled'>申请退货</button>";
                        }else if(d.status == 5) {
                            return "<button class='layui-btn layui-btn-xs layui-btn-danger layui-btn-radius disabled'>未支付</button>";
                        }
                    },sort: true}
            ,{title: '操作', minWidth: 150, toolbar: '#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line',
            id:"teaTable"
        });
        // 监听搜索操作
        form.on('submit(searchBtn)', function (data) {
            //执行搜索重载
            table.reload('teaTable', {
                page: {
                    curr: 1
                }
                , where: {
                    bookname: $("#all").val()
                }
            });
            return false;
        });

        //新增
        form.on('submit(formDemo)', function (data) {
            //执行搜索重载
            $.ajax({
                url:"/order/insertTeacher",
                data:data.field,
                type:"post",
                dataType:"json",
                success:function (reDate){
                    console.log(reDate);
                    if (reDate.code=1){
                        //执行重载
                        table.reload('teaTable', {
                            page: {
                                curr: 2 //重新从第 1 页开始
                            }
                        })
                        layer.closeAll();
                    }else{
                        alert(reDate.msg);
                    }
                }
            })
            return false;
        });

        //工具栏事件
        table.on('toolbar(teaTable)', function(obj){
            switch(obj.event){
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    getOrderStatus();
                    $('#addform')[0].reset(); /*清空表单*/
                    layer.open({
                        content:$('#addform')
                        ,type:1,
                        title:['书籍信息','font-size:25px;'],
                        area:["700px","700px"]
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(teaTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'delete'){
                layer.confirm('确认删除吗', function(index){
                    $.ajax({
                        url:"/order/deleteTeacher"
                        ,type:"post"
                        ,data:{pid:data.pid}
                        ,success:function (a) {
                            if (a.code==1){
                                table.reload("teaTable");
                            }else{
                                layer.msg('失败', {icon: 5});
                            }
                        }
                    })
                    layer.close(index);
                });

            } else if(obj.event === 'edit'){
                getOrderStatus();
                form.val("biaodan", data);
                layer.open({
                    content:$('#addform')
                    ,type:1
                    ,area:['700px','650px']
                    ,skin: 'layui-layer-molv',
                })
            }else if(obj.event === 'send'){
                $.ajax({
                    url:"${pageContext.request.contextPath}/order/updateOrderSta"
                    ,type:"post"
                    ,data:{pid:data.pid,status:1}
                    ,success:function (a) {
                        if (a.code==1){
                            table.reload("teaTable");
                        }else{
                            layer.msg('失败', {icon: 5});
                        }
                    }
                })
            }
        });
        //订单状态下拉
        function getOrderStatus() {
            $("#status").append("<option value='"+0+"'>"+"待发货"+"</option>")
            $("#status").append("<option value='"+1+"'>"+"已发货"+"</option>")
            $("#status").append("<option value='"+2+"'>"+"订单关闭"+"</option>")
            $("#status").append("<option value='"+3+"'>"+"已收货"+"</option>")
            $("#status").append("<option value='"+4+"'>"+"申请退货"+"</option>")
            $("#status").append("<option value='"+5+"'>"+"未付款"+"</option>")
            form.render();
        }
    });
</script>
</body>
</html>
